/**
 * Coryright 2015-2020 www.eyaomall.cn
 * All rights reserved.
 * @author huwenqing
 * @date 2016年8月3日
 *
 */
package com.eyaomall.wxmanage.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.eyaomall.wxmanage.common.helper.MemberHelper;
import com.eyaomall.wxmanage.dao.ArticleCategroyDao;
import com.eyaomall.wxmanage.dao.ArticleDao;
import com.eyaomall.wxmanage.dao.UserDao;
import com.eyaomall.wxmanage.model.po.Article;
import com.eyaomall.wxmanage.model.po.ArticleCategory;
import com.eyaomall.wxmanage.model.po.User;
import com.eyaomall.wxmanage.service.ArticleCategroyService;
import com.lycheeframework.core.cmp.kit.PageHTTPObject;

@Service
public class ArticleCategroyServiceImpl implements ArticleCategroyService {
	
	@Autowired
	private ArticleCategroyDao articleCategroyDao;
	
	@Autowired
	private UserDao userDao;
	
	@Autowired
	private ArticleDao articleDao;
	
	/**
	 * 分类
	 */
	public Object page(ArticleCategory articleCategroy,PageHTTPObject object) {
		return articleCategroyDao.page(articleCategroy,object);
	}
	
	/**
	 * 删除分类
	 */
	public boolean delData(Integer id) {
		ArticleCategory articleCategroy = new ArticleCategory();
		articleCategroy.setId(id);
		articleCategroy.setIsDeleted("y");
		Article article = new Article();
		article.setCategoryId(id);
		int num =  articleDao.count(article);
		if(num > 0 ){			
			return false;
		}
		return articleCategroyDao.update(articleCategroy)>0?true:false ;
	}

	/**
	 * 保存分类
	 */
	public int saveData(ArticleCategory articleCategroy) {
		ArticleCategory categroy = new ArticleCategory();
		User user = new User();
		user.setId(MemberHelper.getId());
		User u = (User) userDao.query(user);
		categroy.setUserId(u.getId());
		categroy.setName(articleCategroy.getName());
		return  (int) articleCategroyDao.insert(categroy);
	}

	/**
	 * 修改分类名
	 */
	public boolean editData(ArticleCategory articleCategroy) {
		Article article = new Article();
		article.setCategoryId(articleCategroy.getId());
		article.setCategoryName(articleCategroy.getName());
		articleDao.update(article);
		return articleCategroyDao.update(articleCategroy)>0?true:false ;
	}

	/**
	 * 加载数据
	 */
	public Object load(ArticleCategory articleCategroy) {
		return articleCategroyDao.list(articleCategroy);
	}

}
